﻿'========================================================================
'功能:群組授權管理頁面,需要有授權的頁面才可以授權不是所有的頁面均可以授權
'作者:andy
'日期: 2011/1/31
'========================================================================

Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.Data.SqlClient
Imports System.Text
Imports System.Data
Partial Class WebForm_Manage_GroupRights
    Inherits BasePage

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            hiUID.Value = ActualUID
            hiDBName.Value = dbName
            If Not ChkProgramRight(1) Then '查詢
                gvMenu.Visible = False
            End If
            If Not ChkProgramRight(2) Then '設定
                gvMenu.Columns(2).Visible = False

            End If
            lblTitle.Text = GetLocalResourceObject("lblTitle")
            ''取得群組代碼選項
            Dim groupBBL As OAMS.BBL.GroupBBL = New OAMS.BBL.GroupBBL()
            Dim dtGroup As DataTable = groupBBL.GetGroupIDdt(dbName)
            ddlGroupID.DataSource = dtGroup
            ddlGroupID.DataBind()




        End If

    End Sub

    
    Protected Sub gvMenu_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles gvMenu.RowCommand
        '設定按鈕
        If e.CommandName = "Select" Then
            If gvMenu.SelectedIndex > -1 Then '有選定時才可以動作
                lblMenuName.Text = gvMenu.Rows(gvMenu.SelectedIndex).Cells(1).Text '設定右方的頁面名稱內容
                gvGroupRights.Visible = True '查出某一頁面的功能鍵資料
                gvGroupRights.DataBind()
            Else
                lblMenuName.Text = ""
                gvGroupRights.Visible = False
            End If
        End If

    End Sub

    Protected Sub gvMenu_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles gvMenu.SelectedIndexChanged
        If gvMenu.SelectedIndex > -1 Then '有選定時才可以動作
            lblMenuName.Text = gvMenu.Rows(gvMenu.SelectedIndex).Cells(1).Text '設定右方的頁面名稱內容
            gvGroupRights.Visible = True '查出某一頁面的功能鍵資料
            gvGroupRights.DataBind()
        Else
            lblMenuName.Text = ""
            gvGroupRights.Visible = False
        End If

    End Sub

    ''' <summary>
    ''' 換頁次時要取消選定的動作
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks>換頁次時要取消選定的動作</remarks>
    Protected Sub gvMenu_PageIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles gvMenu.PageIndexChanged
        gvMenu.SelectedIndex = -1
        lblMenuName.Text = ""
        gvGroupRights.Visible = False


    End Sub

    Protected Sub ddlGroupID_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlGroupID.SelectedIndexChanged
        If gvMenu.SelectedIndex > -1 Then
            gvGroupRights.Visible = True
            gvGroupRights.DataBind()
        Else
            lblMenuName.Text = ""
            gvGroupRights.Visible = False
        End If

    End Sub

    
    Protected Sub gvGroupRights_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles gvGroupRights.DataBound
        If Not ChkProgramRight(3) Then
            For Each gr As GridViewRow In gvGroupRights.Rows

                CType(gr.FindControl("cbUseRight"), CheckBox).Enabled = False
            Next
        End If

    End Sub

    Protected Sub cbUseRight_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim groupBBL As OAMS.BBL.GroupBBL = New OAMS.BBL.GroupBBL()
        Dim ProgramID As Integer = Integer.Parse(gvMenu.SelectedValue)
        Dim SeqNo As Integer = Integer.Parse(CType(sender, CheckBox).ToolTip)
        Dim UseRight = CType(sender, CheckBox).Checked
        groupBBL.UpdateRight(ddlGroupID.SelectedValue, ProgramID, SeqNo, UseRight, UID, dbName)
        gvGroupRights.DataBind()
    End Sub
End Class
